package sz.szsmk.citizencard.mvp.presenter;

import android.content.Context;
import android.util.Log;
import android.widget.Toast;

import com.google.gson.Gson;
import com.youzan.spiderman.utils.MD5Utils;

import org.jetbrains.annotations.Nullable;

import java.util.List;

import javax.inject.Inject;

import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action1;
import rx.schedulers.Schedulers;
import sz.szsmk.citizencard.DaggerApplication;
import sz.szsmk.citizencard.gover.FunctionItem;
import sz.szsmk.citizencard.log.L;
import sz.szsmk.citizencard.model.network.GsdxNetApi;
import sz.szsmk.citizencard.model.network.RxSubscribers;
import sz.szsmk.citizencard.model.network.bean.UpdataVersionReq;
import sz.szsmk.citizencard.model.network.bean.request.AccessTokenRequest;
import sz.szsmk.citizencard.model.network.bean.request.GetOrderOpenid;
import sz.szsmk.citizencard.model.network.bean.request.IBaseRequest;
import sz.szsmk.citizencard.model.network.bean.request.NoticeMainReq;
import sz.szsmk.citizencard.model.network.bean.request.ProtocolsAgreeReq;
import sz.szsmk.citizencard.model.network.bean.request.ProtocolsRequest;
import sz.szsmk.citizencard.model.network.bean.request.ProtocolsShowReq;
import sz.szsmk.citizencard.model.network.bean.request.PushReq;
import sz.szsmk.citizencard.model.network.bean.request.QueryCitizenCardReq;
import sz.szsmk.citizencard.model.network.bean.request.QueryUserCardRequest;
import sz.szsmk.citizencard.model.network.bean.request.RecordUserFunctionReq;
import sz.szsmk.citizencard.model.network.bean.request.UserBehaviorBrowseReq;
import sz.szsmk.citizencard.model.network.bean.request.UserBehaviorReq;
import sz.szsmk.citizencard.model.network.bean.request.VerifyBindNgUserReq;
import sz.szsmk.citizencard.model.network.bean.response.BaseBean;
import sz.szsmk.citizencard.model.network.bean.response.CheckIsChargeRes;
import sz.szsmk.citizencard.model.network.bean.response.GestureValidBean;
import sz.szsmk.citizencard.model.network.bean.response.GetOrderOpenidRes;
import sz.szsmk.citizencard.model.network.bean.response.NoticeMainres;
import sz.szsmk.citizencard.model.network.bean.response.OneWordRes;
import sz.szsmk.citizencard.model.network.bean.response.ProtocolsRes;
import sz.szsmk.citizencard.model.network.bean.response.ProtocolsShowRes;
import sz.szsmk.citizencard.model.network.bean.response.QueryCitizenCardRes;
import sz.szsmk.citizencard.model.network.bean.response.QueryUserCardRes;
import sz.szsmk.citizencard.model.network.bean.response.QueryUserCardResponse;
import sz.szsmk.citizencard.model.network.bean.response.SeleciUserAuthRes;
import sz.szsmk.citizencard.model.network.bean.response.TagConfigRes;
import sz.szsmk.citizencard.model.network.bean.response.UpdataVersionRes;
import sz.szsmk.citizencard.model.network.bean.response.UserInfoRes;
import sz.szsmk.citizencard.model.network.bean.response.VerifyBindNgUserRes;
import sz.szsmk.citizencard.model.network.clarkbean.response.AreaInfoResponse;
import sz.szsmk.citizencard.model.network.dzbean.req.CommonRequest;
import sz.szsmk.citizencard.model.network.dzbean.req.GetOpenIdReq;
import sz.szsmk.citizencard.model.network.dzbean.req.PreAuthThiedReq;
import sz.szsmk.citizencard.model.network.dzbean.req.PreAuthThirdRes;
import sz.szsmk.citizencard.model.network.dzbean.req.QueryDzsmkAgreementReq;
import sz.szsmk.citizencard.model.network.dzbean.res.CheckIsRealName2Res;
import sz.szsmk.citizencard.model.network.dzbean.res.CheckIsRealNameRes;
import sz.szsmk.citizencard.model.network.dzbean.res.GetOpenIdRes;
import sz.szsmk.citizencard.model.network.dzbean.res.PreAuthResult;
import sz.szsmk.citizencard.model.network.dzbean.res.QueryDzsmkAgreeMentRes;
import sz.szsmk.citizencard.mvp.contract.IGoverContact;
import sz.szsmk.citizencard.mvp.contract.IHomeContact;
import sz.szsmk.citizencard.mvp.contract.IMainContact;
import sz.szsmk.citizencard.mvp.contract.IRealNameContact;
import sz.szsmk.citizencard.mvp.contract.IRoutineCardContact;
import sz.szsmk.citizencard.retrofitrxjava.DZSmkAppInit;
import sz.szsmk.citizencard.retrofitrxjava.ErrorAction;
import sz.szsmk.citizencard.retrofitrxjava.NetworkDateSources;
import sz.szsmk.citizencard.retrofitrxjava.SubscribeResult;
import sz.szsmk.citizencard.retrofitrxjava.newversion.ApiCallback;
import sz.szsmk.citizencard.retrofitrxjava.newversion.HttpDateSource;
import sz.szsmk.citizencard.smkretrofit.NetworkDateSource;
import sz.szsmk.citizencard.ui.activity.LoginActivity;
import sz.szsmk.citizencard.util.ACache;
import sz.szsmk.citizencard.util.AndroidUtils;
import sz.szsmk.citizencard.util.Constant;
import sz.szsmk.citizencard.util.ObjectSignatureUtil;
import sz.szsmk.citizencard.util.PubUtils;
import sz.szsmk.citizencard.util.StringUtils;
import sz.szsmk.citizencard.widget.GlobalVariables;

/**
 * Created by wangzhongfu on 2017/6/6.
 */

public class IMainPresenter extends IBasePresenter
        implements IMainContact.IMainPresenter<IMainContact.IMainView> {

    public static String tag = IMainPresenter.class.getSimpleName();

    private GsdxNetApi gsdxNetApi;

    private NetworkDateSource mNetworkDateSource;
    private NetworkDateSources mNetworkDate;

    private GetOpenIdRes getOpenIdRes;

    public static final String LOGIN_TEST = "{\"telephone\":\"@1\",\"agent\":\"@2\"}";

    @Inject
    public IMainPresenter(GsdxNetApi gsdxNetApi) {
        this.gsdxNetApi = gsdxNetApi;

        this.mNetworkDateSource = NetworkDateSource.getInstance();
        this.mNetworkDate = NetworkDateSources.getInstance();
    }

    @Override
    public void sendMainRequest() {

    }

    @Override
    public void checkIsOpenElecCard(String openId) {
        CommonRequest request = new CommonRequest();
        request.setOpenId(openId);
        ObjectSignatureUtil.signaturePreAuthRequest(request);
        String toJson = new Gson().toJson(request);
        L.e(Constant.TAG, "checkIsRealName------>" + toJson);

        mNetworkDateSource.checkIsRealName2(request,new SubscribeResult<CheckIsRealName2Res>(){

            @Override
            protected void onOk(CheckIsRealName2Res preAuthRes) {
                String json = new Gson().toJson(preAuthRes);
                L.e(Constant.TAG, "--------------------" + json);
                if (preAuthRes.getCode().equals("0000")) {
                    CheckIsRealNameRes checkIsRealNameRes = new CheckIsRealNameRes();
                    CheckIsRealNameRes.DataBean bean = new CheckIsRealNameRes.DataBean();
                    bean.setIsRealName(preAuthRes.getData().getIsRealName());
                    checkIsRealNameRes.setData(bean);
                    ((IMainContact.IMainView) mView).checkIsOpenElecCardSuccess(checkIsRealNameRes);
                } else {
                    ((IMainContact.IMainView) mView).checkIsOpenElecCardError(null);
                    PubUtils.popTipOrWarn(DaggerApplication.getIns(),preAuthRes.getMessage() );
                }
            }

            @Override
            protected void onFailure(CheckIsRealName2Res response) {
                super.onFailure(response);
                L.e(Constant.TAG, "--------------------" );
            }
        }, new ErrorAction() {
            @Override
            public void onCall(Throwable throwable) {
                L.e(Constant.TAG, "--------------------" );
            }
        });
    }

    @Override
    public void checkIsCharge() {
//        CommonRequest commonRequest = ObjectSignatureUtil.getCommonRequest();
        CommonRequest commonRequest = new CommonRequest();
        String openId = ACache.get(DaggerApplication.getIns()).getAsString("openId");
        commonRequest.setOpenId(openId);

        ObjectSignatureUtil.signatureZhsz(commonRequest, "");
        String json = new Gson().toJson(commonRequest);
        L.e(Constant.TAG, "checkIsCharge-----" + json);
        mNetworkDateSource.checkIsCharge(commonRequest, new Action1<CheckIsChargeRes>() {
            @Override
            public void call(CheckIsChargeRes ibaseBean) {
                String toJson = new Gson().toJson(ibaseBean);
                L.e(Constant.TAG, "checkIsCharge--->" + toJson);
                ((IMainContact.IMainView) mView).checkIsChargeSucc(ibaseBean);
            }
        }, new ErrorAction() {
            @Override
            public void onCall(Throwable throwable) {
                ((IMainContact.IMainView) mView).checkIsChargeFail();
            }
        });
    }

    /**
     * 跳转电子市民卡的第一步
     * 验证openID
     *
     * @param
     */


    @Override
    public void getOpenId() {

        GetOpenIdReq getOpenIdReq = new GetOpenIdReq();
        String access_token = ACache.get(DaggerApplication.getIns()).getAsString("access_token");
        getOpenIdReq.setUser_type(0);
        getOpenIdReq.setAccess_token(access_token);
        String s = new Gson().toJson(getOpenIdReq);
        L.e(Constant.TAG, "getOpenid----" + s);
        gsdxNetApi.getOpenId(getOpenIdReq)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new RxSubscribers<GetOpenIdRes>() {
                    @Override
                    public void onCompleted() {
                    }

                    @Override
                    protected void _onNext(GetOpenIdRes response) {
                        getOpenIdRes = response;
                        String json = new Gson().toJson(response);
                        L.e(Constant.TAG, "getOpenId---->" + json);
                        String openId = response.getOpenId();
                        ACache.get(DaggerApplication.getIns()).remove("openId");
                        ACache.get(DaggerApplication.getIns()).put("openId", openId + "");
                        ACache.get(DaggerApplication.getIns()).put("userId", response.getUserId() + "");
                        PreAuthResult preAuthResult = new PreAuthResult();
                        preAuthResult.setOpenId(response.getOpenId());
                        GlobalVariables.getInstance(DZSmkAppInit.getInstance().getContext()).setPreAuthResult(DaggerApplication.getIns(), preAuthResult);
                        String openId1 = GlobalVariables.getInstance(DZSmkAppInit.getInstance().getContext()).getPreAuthResult().getOpenId();

//                        PreAuthResult preAuthResult = GlobalVariables.getInstance(DZSmkAppInit.getInstance().getContext()).getPreAuthResult();
//                        String token = preAuthResult.getToken();
//                        PreAuthResult authResult = GlobalVariables.getInstance(DZSmkAppInit.getInstance().getContext()).getPreAuthResult();
//                        PreAuthResult authResult = GlobalVariables.getInstance().getPreAuthResult();

//                        authResult.setOpenId(openId);

                        //2.获取到openid后登陆

//                        queryDzsmkAgreement(openId);
                        if (response.getCode().equals("000000")) {
                            ((IMainContact.IMainView) mView).getOpenIdSucc(response);
                        } else {
                            ((IMainContact.IMainView) mView).getOpenIdFail(response);
                        }
                    }

                    @Override
                    protected void _onError(String message) {
                        Log.e("zdh", "请求失败" + message);
                    }
                });
    }

    @Override
    public void queryDzsmkAgreement(final String openId) {

        QueryDzsmkAgreementReq queryDzsmkAgreementReq = new QueryDzsmkAgreementReq();
        queryDzsmkAgreementReq.setOpenId(openId);
        queryDzsmkAgreementReq.setUserType(0);
        String json = new Gson().toJson(queryDzsmkAgreementReq);
        L.e(Constant.TAG, "queryDzsmkAgreement---->" + json);
        mNetworkDate.queryDzsmkAgreement(queryDzsmkAgreementReq, new SubscribeResult<QueryDzsmkAgreeMentRes>() {
            @Override
            protected void onOk(QueryDzsmkAgreeMentRes response) {
                String toJson = new Gson().toJson(response);
                String channelId = response.getChannelId();
                ACache.get(DaggerApplication.getIns()).put("channelId", channelId);
                L.e(Constant.TAG, "queryDzsmkAgreement---->" + toJson);
                preAuthThird(openId, "2");
            }

            @Override
            protected void onFailure(QueryDzsmkAgreeMentRes response) {
                super.onFailure(response);
                if (response.getCode().equals("000005")) {
                    ACache.get(DaggerApplication.getIns()).put("channelId", "000003");
                    preAuthThird(openId, "2");
                }
                ((IMainContact.IMainView) mView).queryDzsmkAgreementFail(response);
            }
        }, new ErrorAction() {
            @Override
            public void onCall(Throwable throwable) {

            }
        });
    }

    @Override
    public void addPush(String access_token) {
        PushReq pushReq = new PushReq();
        String pushchanne = ACache.get(DaggerApplication.getIns()).getAsString("pushchannel");
        pushReq.setAccessToken(access_token);
        pushReq.setChannelId(pushchanne);
        pushReq.setDeviceType("3");
        String json = new Gson().toJson(pushReq);
        L.e(Constant.MTAG, "-----------------------------------" + json);
        mNetworkDate.addPush(pushReq, new SubscribeResult<BaseBean>() {
            @Override
            protected void onOk(BaseBean response) {
                String toJson = new Gson().toJson(response);

                L.e(Constant.TAG, "-----------------------------------" + toJson);
            }
        }, new ErrorAction() {
            @Override
            public void onCall(Throwable throwable) {

            }
        });
    }


    @Override
    public void checkVersion(String versionName) {
        UpdataVersionReq updataVersionReq = new UpdataVersionReq();
        updataVersionReq.setDeviceName("Android");
//        updataVersionReq.setVersionNo(versionName);
        updataVersionReq.setVersionNo(versionName);
        String toJson = new Gson().toJson(updataVersionReq);
        L.e(Constant.TAG, "提交服务器版本：" + toJson);
        mNetworkDate.getAppVersion(updataVersionReq, new SubscribeResult<UpdataVersionRes>() {
            @Override
            protected void onOk(UpdataVersionRes response) {
                ((IMainContact.IMainView) mView).checkVersionSucc(response);
            }

            @Override
            protected void onFailure(UpdataVersionRes response) {
                super.onFailure(response);
            }
        }, new ErrorAction() {
            @Override
            public void onCall(Throwable throwable) {

            }
        });
    }

    @Override
    public void recordUserFunction(int funId) {
        RecordUserFunctionReq recordUserFunctionReq = new RecordUserFunctionReq();
        recordUserFunctionReq.setFunction_id(funId + "");
        recordUserFunctionReq.setSign("");
        mNetworkDate.recordUserFunction(recordUserFunctionReq, new SubscribeResult<OneWordRes>() {
            @Override
            protected void onOk(OneWordRes response) {

            }
        }, new ErrorAction() {
            @Override
            public void onCall(Throwable throwable) {

            }
        });
    }

    @Override
    public void getGestureIsOpen(final Context context) {
        final String access_token = ACache.get(DaggerApplication.getIns()).getAsString("access_token");
        if (StringUtils.isBlank(access_token)) {
            return;
        }
        IBaseRequest baseRequest = new IBaseRequest();
        baseRequest.setAccess_token(access_token);
        mNetworkDate.gestureValid(baseRequest, new SubscribeResult<GestureValidBean>() {
            @Override
            protected void onOk(GestureValidBean response) {
                Constant.isOpen = response.getIsOpen();
            }

            @Override
            protected void onFailure(GestureValidBean response) {
                super.onFailure(response);
            }

            @Override
            protected void onNext(GestureValidBean response) {
                super.onNext(response);
            }
        }, new ErrorAction() {
            @Override
            public void onCall(Throwable throwable) {
            }
        });
    }

    @Override
    public void getGetOrderId(String url, String type) {
        String access_token = ACache.get(DaggerApplication.getIns()).getAsString("access_token");

        GetOrderOpenid getOrderOpenid = new GetOrderOpenid();
        getOrderOpenid.setTag("HUIMIN");
        getOrderOpenid.setAccess_token(access_token);
        String json = new Gson().toJson(getOrderOpenid);
        L.e(Constant.TAG, "getOrderOpenid----->" + json);
        mNetworkDate.getOrderOpenid(getOrderOpenid, new SubscribeResult<GetOrderOpenidRes>() {
            @Override
            protected void onOk(GetOrderOpenidRes response) {
                String toJson = new Gson().toJson(response);
                Constant.EXTENT = response.getExtend();
                ACache.get(DaggerApplication.getIns()).put("mextend", response.getExtend());
            }

            @Override
            protected void onNext(GetOrderOpenidRes response) {
                super.onNext(response);
                String toJson = new Gson().toJson(response);
                L.e(Constant.TAG, "-------------" + toJson);
            }

            @Override
            protected void onFailure(GetOrderOpenidRes response) {
                super.onFailure(response);
                String toJson = new Gson().toJson(response);
                if (response.getCode().equals("0000")) {

                    ACache.get(DaggerApplication.getIns()).remove("mextend");
                    ACache.get(DaggerApplication.getIns()).put("mextend", response.getExtend());
                }
                L.e(Constant.TAG, "-------------" + toJson);
            }
        }, new ErrorAction() {
            @Override
            public void onCall(Throwable throwable) {
            }
        });
    }

    @Override
    public void getAuthType() {
        AccessTokenRequest accessTokenRequest = new AccessTokenRequest();
        mNetworkDate.selectUserAuth(accessTokenRequest, new SubscribeResult<SeleciUserAuthRes>() {
            @Override
            protected void onOk(SeleciUserAuthRes response) {
                List<SeleciUserAuthRes.AuthTypeListBean> authTypeList = response.getAuthTypeList();
//                SeleciUserAuthRes.AuthTypeListBean authTypeListBean = authTypeList.get(0);
                /*1.社保 2.公积金 3 桂花分*/
                SeleciUserAuthRes.AuthTypeListBean sbAuth = authTypeList.get(0);
                SeleciUserAuthRes.AuthTypeListBean gjjAuth = authTypeList.get(1);
                SeleciUserAuthRes.AuthTypeListBean ghfAuth = authTypeList.get(2);
                //0 未授权  1.已授权  2.未实名

                Constant.GHF_AUTH = ghfAuth.getIsAuth();
                Constant.SB_AUTH = sbAuth.getIsAuth();
                Constant.GJJ_AUTH = gjjAuth.getIsAuth();

            }

            @Override
            protected void onFailure(SeleciUserAuthRes response) {
                super.onFailure(response);
//                Toast.makeText(DaggerApplication.getIns(), response.getMessage(), Toast.LENGTH_SHORT).show();
            }
        }, new ErrorAction() {
            @Override
            public void onCall(Throwable throwable) {

            }
        });
    }

    @Override
    public void queryUserCard(String type, String origin) {
        QueryUserCardRequest cardRequest = new QueryUserCardRequest();
        String access_token = ACache.get(DaggerApplication.getIns()).getAsString("access_token");
        cardRequest.setAccess_token(access_token);
        cardRequest.setType("00");
        cardRequest.setOrigin(origin);
        String json = new Gson().toJson(cardRequest);
        mNetworkDate.queryUserCardInfo(cardRequest, new SubscribeResult<QueryUserCardRes>() {
            @Override
            protected void onOk(QueryUserCardRes response) {
                String json = new Gson().toJson(response);
                L.e(Constant.TAG, "queryUserCard----->" + json);
                ((IMainContact.IMainView) mView).queryUserCardSuccess(response);
            }

            @Override
            protected void onFailure(QueryUserCardRes response) {
                super.onFailure(response);
            }

            @Override
            protected void onNext(QueryUserCardRes response) {
                super.onNext(response);
            }
        }, new ErrorAction() {
            @Override
            public void onCall(Throwable throwable) {
            }
        });
    }

    @Override
    public void getConfig() {
        IBaseRequest iBaseRequest = new IBaseRequest();
        mNetworkDate.getConfig(iBaseRequest, new SubscribeResult<TagConfigRes>() {
            @Override
            protected void onOk(TagConfigRes response) {
                if (response != null) {
                    Constant.SZ_TAG = response.getTag();
                    Constant.SZ_URL = response.getUrl();
                }
            }

            @Override
            protected void onFailure(TagConfigRes response) {
                super.onFailure(response);
            }
        }, new ErrorAction() {
            @Override
            public void onCall(Throwable throwable) {

            }
        });
    }



    @Override
    public void queryCitizenCard() {
        QueryUserCardRequest cardRequest = new QueryUserCardRequest();
        String access_token = ACache.get(DaggerApplication.getIns()).getAsString("access_token");
        cardRequest.setAccess_token(access_token);
        cardRequest.setType("00");
        //来源（0 全部卡（去重实名的绑定卡+实名卡）1 实名的卡 2 绑定的卡（去重实名卡） 3 绑定的卡（不去重实名卡））
        cardRequest.setOrigin("0");
        String json = new Gson().toJson(cardRequest);
        mNetworkDate.queryUserCardInfo(cardRequest, new SubscribeResult<QueryUserCardRes>() {
            @Override
            protected void onOk(QueryUserCardRes response) {
                String json = new Gson().toJson(response);
                L.e(Constant.TAG, "queryUserCard----->" + json);
                ((IMainContact.IMainView) mView).queryUserCardSuccess(response);
            }

            @Override
            protected void onFailure(QueryUserCardRes response) {
                super.onFailure(response);
            }

            @Override
            protected void onNext(QueryUserCardRes response) {
                super.onNext(response);
            }
        }, new ErrorAction() {
            @Override
            public void onCall(Throwable throwable) {
            }
        });
    }


    public void preAuthThird(String openId, final String id) {
        PreAuthThiedReq preAuthThiedReq = new PreAuthThiedReq();
        preAuthThiedReq.setMobileNumber(getOpenIdRes.getMobile() + "");
        preAuthThiedReq.setOpenId(openId);
        preAuthThiedReq.setUserId(getOpenIdRes.getUserId() + "");
        preAuthThiedReq.setPhotoUrl("");
        String channelId = ACache.get(DaggerApplication.getIns()).getAsString("channelId");
        preAuthThiedReq.setChannelId(channelId);

        ObjectSignatureUtil.signaturePreAuthRequest(preAuthThiedReq);
        String toJson = new Gson().toJson(preAuthThiedReq);
        L.e(Constant.TAG, "------->" + toJson);
        mNetworkDateSource.preAuthThird(preAuthThiedReq, new Action1<PreAuthThirdRes>() {
            @Override
            public void call(PreAuthThirdRes preAuthRes) {
                String code = preAuthRes.getCode();
                if (code.equals("0000")) {
                    PreAuthThirdRes.DataBean data = preAuthRes.getData();
                    String json = new Gson().toJson(data);
                    ACache.get(DaggerApplication.getIns()).put("token", preAuthRes.getData().getToken());
                    PreAuthResult preAuthResult = new Gson().fromJson(json, PreAuthResult.class);
                    GlobalVariables.getInstance(DZSmkAppInit.getInstance().getContext()).setPreAuthResult(DaggerApplication.getIns(), preAuthResult);
                    PreAuthResult authResult = GlobalVariables.getInstance(DZSmkAppInit.getInstance().getContext()).getPreAuthResult();
                    String token = authResult.getToken();
                    ((IMainContact.IMainView) mView).preAuthThirdSucc(id);
                    L.e(Constant.MTAG, "存储的token：" + token);

                } else {
                    ((IMainContact.IMainView) mView).preAuthThirdFail(preAuthRes);
                }


            }
        }, new ErrorAction() {
            @Override
            public void onCall(Throwable throwable) {
                L.e(Constant.TAG, "--------------------" + throwable.getMessage());
            }
        });

    }

    public void userBehaviorBrowse(int id) {
        UserBehaviorBrowseReq userBehaviorBrowseReq = new UserBehaviorBrowseReq();
        userBehaviorBrowseReq.setModularId(id);
        userBehaviorBrowseReq.setAccessToken(ACache.get(DaggerApplication.getIns()).getAsString("access_token"));

        mNetworkDate.userBehaviorBrowse(userBehaviorBrowseReq, new Action1<BaseBean>() {
            @Override
            public void call(BaseBean baseBean) {
                Log.i("userBehaviorBrowse","ok---------");
            }
        }, new ErrorAction() {
            @Override
            public void onCall(Throwable throwable) {
            }
        });
    }

    public void userBehaviorActivity(){
        UserBehaviorReq baseRequest = new UserBehaviorReq();
        baseRequest.setAccessToken(ACache.get(DaggerApplication.getIns()).getAsString("access_token"));
        baseRequest.setDeviceId(AndroidUtils.getAndroidId(DaggerApplication.getIns()));
        mNetworkDateSource.userBehaviorActive(baseRequest, new SubscribeResult<BaseBean>() {
            @Override
            protected void onOk(BaseBean response) {
                Log.i("tag","ok");
            }

            @Override
            protected void onFailure(BaseBean response) {
                super.onFailure(response);
            }
        }, new ErrorAction() {
            @Override
            public void onCall(Throwable throwable) {

            }
        });
    }

    //校验金融 是否授权
    public void verifyBindNgUser(Object ng_url) {
        // 判断是否绑定NG用户
        VerifyBindNgUserReq verifyBindNgUserReq = new VerifyBindNgUserReq();
        String access_token = ACache.get(DaggerApplication.getIns()).getAsString("access_token");
        verifyBindNgUserReq.setAccess_token(access_token);
        verifyBindNgUserReq.setBiz_type("01");

        mNetworkDate.verifyBindNgUser(verifyBindNgUserReq, new Action1<VerifyBindNgUserRes>() {
            @Override
            public void call(VerifyBindNgUserRes verifyBindNgUserRes) {
                ((IMainContact.IMainView) mView).verifyBindNgUserSucc(verifyBindNgUserRes,ng_url);
            }
        }, new ErrorAction() {
            @Override
            public void onCall(Throwable throwable) {
            }
        });
    }

    //校验我的钱包  是否授权
    public void verifybindWalletuser(Object ng_url) {
        // 判断 我的钱包 是否开启
        VerifyBindNgUserReq verifyBindNgUserReq = new VerifyBindNgUserReq();
        String access_token = ACache.get(DaggerApplication.getIns()).getAsString("access_token");
        verifyBindNgUserReq.setAccess_token(access_token);
        verifyBindNgUserReq.setBiz_type("02");

        mNetworkDate.verifyBindNgUser(verifyBindNgUserReq, new Action1<VerifyBindNgUserRes>() {
            @Override
            public void call(VerifyBindNgUserRes verifyBindNgUserRes) {
                ((IMainContact.IMainView) mView).verifybindWalletuserSucc(verifyBindNgUserRes,ng_url);
            }
        }, new ErrorAction() {
            @Override
            public void onCall(Throwable throwable) {
            }
        });
    }


    //用户确认授权接口   绑定NG金融
    public void toBindNgUser(Object ng_url) {
        VerifyBindNgUserReq verifyBindNgUserReq = new VerifyBindNgUserReq();
        String access_token = ACache.get(DaggerApplication.getIns()).getAsString("access_token");
        verifyBindNgUserReq.setAccess_token(access_token);
        verifyBindNgUserReq.setBiz_type("01");

        mNetworkDate.toBindNgUser(verifyBindNgUserReq, new Action1<VerifyBindNgUserRes>() {
            @Override
            public void call(VerifyBindNgUserRes verifyBindNgUserRes) {
                if(verifyBindNgUserRes.getCode().equals("000000")){
                    ((IMainContact.IMainView) mView).toBindNgUserSucc(verifyBindNgUserRes,ng_url);
                }
            }
        }, new ErrorAction() {
            @Override
            public void onCall(Throwable throwable) {
            }
        });
    }


    //用户确认授权接口   绑定NG金融
    public void toBindWallet(Object ng_url) {
        VerifyBindNgUserReq verifyBindNgUserReq = new VerifyBindNgUserReq();
        String access_token = ACache.get(DaggerApplication.getIns()).getAsString("access_token");
        verifyBindNgUserReq.setAccess_token(access_token);
        verifyBindNgUserReq.setBiz_type("02");

        mNetworkDate.toBindNgUser(verifyBindNgUserReq, new Action1<VerifyBindNgUserRes>() {
            @Override
            public void call(VerifyBindNgUserRes verifyBindNgUserRes) {
                if(verifyBindNgUserRes.getCode().equals("000000")){
                    ((IMainContact.IMainView) mView).toBindWalletUserSucc(verifyBindNgUserRes,ng_url);
                }
            }
        }, new ErrorAction() {
            @Override
            public void onCall(Throwable throwable) {
            }
        });
    }

    //获取桂花分拼接参数
    public void getGetOrderIdForGHF() {
        String access_token = ACache.get(DaggerApplication.getIns()).getAsString("access_token");
        GetOrderOpenid getOrderOpenid = new GetOrderOpenid();
        getOrderOpenid.setAccess_token(access_token);
        getOrderOpenid.setTag("GUIHUAFEN");
        mNetworkDate.getOrderOpenid(getOrderOpenid, new SubscribeResult<GetOrderOpenidRes>() {
            @Override
            protected void onOk(GetOrderOpenidRes response) {
                Constant.EXTENT_GHF = response.getExtend();
            }

            @Override
            protected void onNext(GetOrderOpenidRes response) {
                super.onNext(response);
            }

            @Override
            protected void onFailure(GetOrderOpenidRes response) {
                super.onFailure(response);
            }
        }, new ErrorAction() {
            @Override
            public void onCall(Throwable throwable) {
            }
        });
    }

    //跳转 公积金 桂花分 社保
    public void selectUserAuth(final String type ) {
        AccessTokenRequest accessTokenRequest = new AccessTokenRequest();
        mNetworkDate.selectUserAuth(accessTokenRequest, new SubscribeResult<SeleciUserAuthRes>() {
            @Override
            protected void onOk(SeleciUserAuthRes response) {
                ((IMainContact.IMainView) mView).selectUserAuthSucc(response,type);
            }

            @Override
            protected void onFailure(SeleciUserAuthRes response) {
                super.onFailure(response);
                Toast.makeText(DaggerApplication.getIns(), response.getMessage(), Toast.LENGTH_SHORT).show();
            }
        }, new ErrorAction() {
            @Override
            public void onCall(Throwable throwable) {

            }
        });
    }

    //根据场景获取协议
    @Override
    public void getProtocols(String sceneNo) {
        ProtocolsRequest protocolsRequest = new ProtocolsRequest();
        protocolsRequest.setSceneNo(sceneNo);

        mNetworkDate.getProtocols(protocolsRequest, new SubscribeResult<ProtocolsRes>() {

            @Override
            protected void onOk(ProtocolsRes response) {
                ((IMainContact.IMainView) mView).getProtocolsSucc(response);
            }
        }, new ErrorAction() {
            @Override
            public void onCall(Throwable throwable) {
                ((IMainContact.IMainView) mView).getProtocolsFail();
            }
        });
    }


    //协议是否显示

    public void showProtocols(String sceneNo){
        ProtocolsShowReq protocolsShowReq=new ProtocolsShowReq();
        protocolsShowReq.setAccess_token(ACache.get(DaggerApplication.getIns()).getAsString("access_token"));
        protocolsShowReq.setSceneNo(sceneNo);
        mNetworkDate.showProtocols(protocolsShowReq, new SubscribeResult<ProtocolsShowRes>() {
            @Override
            protected void onOk(ProtocolsShowRes response) {
                ((IMainContact.IMainView) mView).showProtocolsSucc(response);
            }
        }, new ErrorAction() {
            @Override
            public void onCall(Throwable throwable) {
                ((IMainContact.IMainView) mView).showProtocolsFail();
            }
        });

    }

    //同意协议上传
    @Override
    public void addUserAppAgreementRecord(String clientVersion,String operateSystem,String sceneNo){
        ProtocolsAgreeReq protocolsAgreeReq=new ProtocolsAgreeReq();
        protocolsAgreeReq.setAccess_token(ACache.get(DaggerApplication.getIns()).getAsString("access_token"));
        protocolsAgreeReq.setClientVersion(clientVersion);
        protocolsAgreeReq.setOperateSystem(operateSystem);
        protocolsAgreeReq.setSceneNo(sceneNo);
        mNetworkDate.addUserAppAgreementRecord(protocolsAgreeReq, new SubscribeResult<BaseBean>() {
            @Override
            protected void onOk(BaseBean response) {
                ((IMainContact.IMainView) mView).addUserAppAgreementRecordSucc(response);
            }
        }, new ErrorAction() {
            @Override
            public void onCall(Throwable throwable) {
                ((IMainContact.IMainView) mView).addUserAppAgreementRecordFail();
            }
        });


    }


    //获取用户实名信息（桂花分）
    public void getPersonInfomation(String sign){
        CommonRequest commonRequest = new CommonRequest();
        commonRequest.setSign(sign);
        commonRequest.setAccess_token(ACache.get(DaggerApplication.getIns()).getAsString("access_token"));
        mNetworkDate.getUserCom(commonRequest, new SubscribeResult<UserInfoRes>() {
            @Override
            protected void onOk(UserInfoRes response) {
                Log.i("getPersonInfomation",response.toString());
                ((IMainContact.IMainView) mView).getUserComSucc(response);
            }
        }, new ErrorAction() {
            @Override
            public void onCall(Throwable throwable) {

            }
        });
    }



}